package com.yy.jhl.ui.manager.presenter;

import com.google.gson.Gson;
import com.yy.common.commonutils.StringUtil;
import com.yy.jhl.api.Api;
import com.yy.jhl.api.RxSubscriber;
import com.yy.jhl.app.AppConstant;
import com.yy.jhl.bean.FunctionInfo;
import com.yy.jhl.bean.ProjectInfo;
import com.yy.jhl.bean.UpdateInfo;
import com.yy.jhl.ui.manager.contract.FunctionContract;
import com.yy.jhl.ui.manager.contract.MenuOneContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.ResponseBody;

/**
 * Created by Ellis.Li on 2017/8/30.
 */

public class FunctionPresenter extends FunctionContract.Presenter {
    @Override
    public void getList(String versionName) {
        Map<String, Object> requestMap = new HashMap<>();
        requestMap.put("current",versionName);
        mRxManage.addSubscription(Api.getDefault().getFunctionList(requestMap), new RxSubscriber<ResponseBody>(mContext,true) {
            @Override
            protected void _onNext(String result) {
                FunctionInfo projectInfo = new Gson().fromJson(result,FunctionInfo.class);
                mView.getSuccess(projectInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getFail();
            }
        });
    }

    @Override
    public void updateApk(final boolean isShow) {
        Map<String, Object> requestMap = new HashMap<>();
        mRxManage.addSubscription(Api.getDefault().updateApk(requestMap), new RxSubscriber<ResponseBody>(mContext,isShow) {
            @Override
            protected void _onNext(String result) {
                UpdateInfo updateInfo = new Gson().fromJson(result,UpdateInfo.class);
                mView.getUpdateApkSuccess(isShow,updateInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getFail();
            }
        });
    }
}
